﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sherwood.SignOn.Server;

namespace Sherwood.SignOn.Client
{
    /// <summary>
    /// Provides access to the SSO client configuration parameters.
    /// </summary>
    public class ClientConfig
    {
        /// <summary>
        /// Base URL to SSO Server (e.g. https://login.sherwood.codeplex.com)
        /// </summary>
        public string SsoServerBaseUrl
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoServerBaseUrl"];
            }
        }

        /// <summary>
        /// SSO server's public RSA key
        /// </summary>
        public string SsoServerRsaPublicKey
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoServerRsaPublicKey"];
            }
        }

        /// <summary>
        /// SSO client's unique identifier
        /// </summary>
        public string SsoClientCode
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoClientCode"];
            }
        }

        /// <summary>
        /// The number of seconds an sso ticket should be treated as valid when comparing the timestamp
        /// sent with the ticket with the current time.
        /// This timeout should take the possibility of different times on different servers into account.
        /// </summary>
        public int SsoTicketValidityInSeconds
        {
            get
            {
                int requestValidityInSeconds = 0;
                int.TryParse(System.Configuration.ConfigurationManager.AppSettings["SsoTicketValidityInSeconds"], out requestValidityInSeconds);
                return requestValidityInSeconds;
            }
        }

        /// <summary>
        /// Gets the domain scope of cookies used to maintain user session locally.
        /// This property can be used to allow clients to provide session management for 
        /// multiple subdomains.
        /// </summary>
        public string SsoClientCookieDomain
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoClientCookieDomain"];
            }
        }

        /// <summary>
        /// SSO client's public RSA key
        /// </summary>
        public string SsoClientRsaPublicKey
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoClientRsaPublicKey"];
            }
        }

        /// <summary>
        /// SSO client's private RSA key.
        /// This should never be made available to 3rd parties.
        /// </summary>
        public string SsoClientRsaPrivateKey
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoClientRsaPrivateKey"];
            }
        }

        /// <summary>
        /// Template of Url that sign on server should call upon successful sign on.
        /// This value may contain the following replacement parameters:
        /// [Host] - replaced with current host name
        /// [CurrentUrl] - replaced by the current Url
        /// [UrlEncodedCurrentUrl] - replaced by a URL encoded version of the current request url.
        /// </summary>
        public string SsoClientSignOnUrl
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoClientSignOnUrl"];
            }
        }

        /// <summary>
        /// Template of Url that sign on server should call upon successful sign on.
        /// This value may contain the following replacement parameters:
        /// [Host] - replaced with current host name
        /// </summary>
        public string SsoClientSignOffUrl
        {
            get
            {
                return System.Configuration.ConfigurationManager.AppSettings["SsoClientSignOffUrl"];
            }
        }
    }
}
